package com.lswms.modules.lswms.dao.receipt;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.lswms.common.dao.BaseDao;
import com.lswms.modules.lswms.entity.receipt.ReceiptEntity;
import com.lswms.modules.lswms.entity.receipt.ReceiptdetailEntity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 收货明细
 *
 * @author DX sunlightcs@gmail.com
 * @since 1.0.0 2021-06-13
 */
@Mapper
public interface ReceiptdetailDao extends BaseDao<ReceiptdetailEntity> {
        public Integer getReceiptdetailMaxLine(@Param("receiptkey") String receiptkey) ;

        void deleteByReceiptkey(@Param("receiptkey") String receiptkey);

        @Select(value ="select lswms_receiptdetail.* ,  lswms_codelist.listname  statusstr   ,lswms_sku.descr , lswms_sku.factorycdoe factorycdoe "
        		+ "from lswms_receiptdetail lswms_receiptdetail "
        		+ "    		left join lswms_codelist  on lswms_receiptdetail.status = lswms_codelist.list and lswms_codelist.code='receiptstatus' "
        		+ "			left join lswms_sku   on lswms_receiptdetail.sku = lswms_sku.sku  ${ew.customSqlSegment}")
		public IPage<ReceiptdetailEntity> selectPageBySql(IPage<ReceiptdetailEntity> page,
				@Param(Constants.WRAPPER)QueryWrapper<ReceiptdetailEntity> wrapper);

        @Select(value ="select lswms_receiptdetail.* ,lswms_receiptdetail.actqty receiptqty, lswms_codelist.listname  statusstr   ,lswms_sku.descr , lswms_sku.factorycdoe factorycdoe,"
        		+ " lswms_sku.isuniquecode  isunique , lswms_sku.price  "
        		+ " from lswms_receiptdetail lswms_receiptdetail "
        		+ "    		left join lswms_codelist  on lswms_receiptdetail.status = lswms_codelist.list and lswms_codelist.code='receiptstatus' "
        		+ "			left join lswms_sku   on lswms_receiptdetail.sku = lswms_sku.sku where lswms_receiptdetail.id = #{id}")
		public ReceiptdetailEntity selectByIdBySql(@Param("id")Long id);
}
